package com.amzing.dynamicrulesshardingjdbc.config.datasource;

import lombok.Generated;
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;

/**
 *
 * @see ShardingDataSourceFactory
 */
public class DynamicRulesShardingDataSourceFactory {

    public static DataSource createDataSource(Map<String, DataSource> dataSourceMap, ShardingRuleConfiguration shardingRuleConfig, Properties props) throws SQLException {
        return new DynamicRulesDatasource(dataSourceMap, new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()), props);
    }

    @Generated
    private DynamicRulesShardingDataSourceFactory() {
    }

}
